<template>
  <div class="pageTwo">
    <h1>{{ $t('page2.title') }}</h1>
    <div class="bigBOx">
      <div class="topBox">  <span class="analysis">{{ $t('page2.Fault_Type_Analysis') }}</span>
        <div class="rightBox">  
          <!-- <span>{{ $t('page2.Fault_Type_Analysis') }}</span> -->
          <RightBoxTable :key="updateKey"></RightBoxTable>
        </div>

        <div class="box-9">
          <el-checkbox-group
            v-model="checkList"
            @change="changeChecked"
            size="medium "
          >
          <el-checkbox class="checked1" label="1">{{ $t('checkbox.Running') }}</el-checkbox>
            <el-checkbox class="checked2" label="0">{{ $t('checkbox.Idle') }}</el-checkbox>
            <el-checkbox class="checked4" label="3">{{ $t('checkbox.Failure') }}</el-checkbox>
            <el-checkbox class="checked3" label="2">{{ $t('checkbox.Downtime') }}</el-checkbox>
          </el-checkbox-group>
          <dv-decoration-7 style="width: auto; height: 30px" class="span"
          >{{ $t('page2.Equipment_Status_Monitoring') }}</dv-decoration-7
          >
          <el-radio-group
            v-model="selsectTime"
            size="small"
            class="el-radio-time"
            @change="changeTime(selsectTime)"
          >
          <el-radio-button label="1">{{ $t('radio.day') }}</el-radio-button>
            <el-radio-button label="2">{{ $t('radio.week') }}</el-radio-button>
            <el-radio-button label="3">{{ $t('radio.month') }}</el-radio-button>
          </el-radio-group>
        </div>
        <dv-border-box-12>
          <div class="itembox">
            <p style="background: linear-gradient(to top, #009dff, #0245ab)">
              CNC
            </p>
            <cncTable :AnalyseAloneList1="AnalyseAloneList1" :key="updateKey"></cncTable>
          </div>
          <div class="itembox">
            <p style="background: linear-gradient(to top, #00b5ba, #00888c)">
              CAM
            </p>
            <camTable :AnalyseAloneList2="AnalyseAloneList2" :key="updateKey"></camTable>
          </div>
          <div class="itembox">
            <p style="background: linear-gradient(to top, #83b533, #7d8d50)">
              {{ $t('page2.Secondary_Processing') }}
            </p>
            <ctwoTable :AnalyseAloneList3="AnalyseAloneList3" :key="updateKey"></ctwoTable>
          </div>
        </dv-border-box-12>
      </div>

      <dv-border-box-13 class="leftCenterline">
        <p class="text text1">{{ $t('page2.Equipment_Utilization_Trend') }}</p>
        <left-center-line :key="updateKey"/>
      </dv-border-box-13>
    </div>

    <div style="margin-top: 1.8%">
      <dv-decoration-7
        style="width: auto; height: 20px; margin-left: -38%"
        class="text"
        >{{ $t('page2.Equipment_Utilization_Monitoring') }}</dv-decoration-7
      >
      <el-radio-group
        v-model="selsectTime1"
        size="small"
        class="el-radio-time1"
        @change="changeTime1(selsectTime1)"
      >
      <el-radio-button label="1">{{ $t('radio.day') }}</el-radio-button>
      <el-radio-button label="2">{{ $t('radio.week') }}</el-radio-button>
      <el-radio-button label="3">{{ $t('radio.month') }}</el-radio-button>
      </el-radio-group>
      <div class="itemPie">
        <pieCnc
          class="pie"
          :AnalyseDayList1="AnalyseDayList1"
          :key="updateKey"
        ></pieCnc>
        <pieCam
          class="pie"
          :AnalyseDayList2="AnalyseDayList2"
          :key="updateKey2"
        ></pieCam>
        <pieTwo
          class="pie"
          :AnalyseDayList3="AnalyseDayList3"
          :key="updateKey3"
        ></pieTwo>
      </div>
    </div>
  </div>
</template>

<script>
import { getEquipmentAnalyseDay, getEquipmentAnalyseAlone } from "@/api/index";
import leftCenterLine from "../components/sysm/leftCenterLine.vue";
import RightBoxTable from "../components/sysm/rightBoxTable.vue";
import camTable from "../components/sysm/camTable.vue";
import cncTable from "../components/sysm/cncTable.vue";
import ctwoTable from "../components/sysm/ctwoTable.vue";
import pieCnc from "../components/sysm/pieCnc.vue";
import pieCam from "../components/sysm/pieCam.vue";
import pieTwo from "../components/sysm/pieTwo.vue";
export default {
  name: "pageTwo",
  components: {
    leftCenterLine,
    RightBoxTable,
    camTable,
    cncTable,
    ctwoTable,
    pieCnc,
    pieCam,
    pieTwo,
  },
  data() {
    return {
      selsectTime: "1",
      selsectTime1: "1",
      updateKey: 1,
      updateKey2: 2,
      updateKey3: 3,
      checkList: ["0", "1", "2", "3"],
      AnalyseDayList1: {},
      AnalyseDayList2: {},
      AnalyseDayList3: {},
      AnalyseAloneList1: [],
      AnalyseAloneList2: [],
      AnalyseAloneList3: [],
      datas: [],
    };
  },
  created() {
    this.changeTime1(this.selsectTime1);
    this.changeTime(this.selsectTime);
  },
  watch: {
    '$i18n.locale': {
      handler(newLocale) {
        this.$nextTick(() => {
       this.updateKey += 1;
    });
      },
      immediate: true, // 立即执行一次
    },
  },
  mounted() {},
  methods: {
    //多选框
    changeChecked(val) {
      this.checkList = val;
      this.changeTime(sessionStorage.getItem("value"));
    },
    //时间选择-设备状态监测
    changeTime(value) {
      sessionStorage.setItem("value", value);
      this.AnalyseAloneList1 = [];
      this.AnalyseAloneList2 = [];
      this.AnalyseAloneList3 = [];
      let data = [];
      getEquipmentAnalyseAlone(value).then((res) => {
        this.datas = res.data;
        this.datas.map((item, index) => {
          this.checkList.includes(item.state) ? data.push(item) : "";
          return data;
        });
        data.forEach((item) => {
          if (item.workshopId == 16) {
            this.AnalyseAloneList1.push(item);
          } else if (item.workshopId == 17) {
            this.AnalyseAloneList2.push(item);
          } else if (item.workshopId == 15) {
            this.AnalyseAloneList3.push(item);
          }
        });
      });
    },
    //时间选择-设备利用率监测
    changeTime1(value) {
      sessionStorage.setItem("value1", value);
      getEquipmentAnalyseDay(value).then((res) => {
        if (res.code == 200) {
          res.data.forEach((item) => {
            if (item.workshopId == 16) {
              this.AnalyseDayList1 = item;
            } else if (item.workshopId == 17) {
              this.AnalyseDayList2 = item;
            } else if (item.workshopId == 15) {
              this.AnalyseDayList3 = item;
            }
          });
          this.$nextTick(() => {
            this.updateKey += 1;
            this.updateKey2 += 2;
            this.updateKey3 += 3;
          });
        }
      });
      this.timer = setTimeout(() => {
        this.changeTime1(sessionStorage.getItem("value1"));
      }, 1200000);
    },
  },
};
</script>

<style lang="scss" scoped>
h1 {
  position: absolute;
  color: #66bfda;
  font-size: 2rem;
  width: auto;
  font-weight: 700;
  line-height: 1rem;
  margin: -30px 660px;
  z-index: 9999;
  letter-spacing: 3px;
}
span {
  font-size: 18px;
  line-height: 25px;
  margin: 0px;
  font-weight: 700;
}
.span {
  position: absolute;
  margin: -25px 0 0 20px;
  font-size: 18px;
  font-weight: 700;
}
.text {
  font-size: 18px;
  font-weight: 700;
}
.text1 {
  margin: -35px 0 0 65px;
}
.pageTwo {
  z-index: 999;
  width: 100%;
  height: 100%;
  padding: 0 25px;
  display: flex;
}
.topBox {
  width: 100%;
  height: 45vh;
  display: flex;
  justify-content: space-between;
  margin-top: 3%;
}

.rightBox {
  padding: 75px 30px;
  width: 43%;
  height: 49vh;
  margin-top: -2.8%;
  background: url("~@/assets/img/rightBox1.png") no-repeat;
  background-size: 100% 100%;
}
.leftCenterline {
  margin-top: 2%;
  padding: 20px 0;
  height: 40vh;
  width: 100%;
}
.box-9 {
  position: absolute;
  margin: 0px 0 0 600px;
}
.dv-border-box-12 {
  width: 56%;
  height: 45vh;
  margin-top: 1.5%;
  .itembox {
    width: 98%;
    margin-left: 1%;
    margin-top: 1.1%;
    height: 30%;
    p {
      width: 100%;
      height: 24%;
      line-height: 30px;
      text-align: center;
      font-size: 18px;
      color: #bfe7f3;
      font-weight: 700;
      padding: 0;
      margin: 0;
    }
  }
}

.dv-border-box-9 {
  width: 22%;
  height: 88vh;
  margin-top: 1.5%;
  margin-left: 20px;
  .itemPie {
    width: 90%;
    margin-left: 6%;
    // margin-top: 6%;
    height: 93%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    .pie {
      width: 100%;
      height: 33%;
    }
  }
}

.bigBOx {
  width: 74%;
  height: 100vh;
  margin-left: 1%;
}

::v-deep .el-radio-button__inner {
  background: #14304c;
  color: #75e9f3;
  font-size: 14px !important;
  width: 48px;
  height: 20px !important;
  border: none;
  text-align: center;
  line-height: 5px;
}
.el-radio-time {
  // position: absolute;
  margin: -40px 0 0 300px;
}

.el-checkbox-group {
  margin-left: 520px;
}
::v-deep .el-checkbox {
  width: 30px;
  .el-checkbox__label {
    color: #8993f2 !important;
    font-size: 14px !important;
    // margin-top: 8px;
    margin-left: -8px !important;
  }
}
::v-deep .checked1 {
  .el-checkbox__input {
    &.is-checked {
      .el-checkbox__inner {
        background-color: #11ff9d;
        border-color: #11ff9d;
      }
    }
  }
}
::v-deep .checked2 {
  .el-checkbox__input {
    &.is-checked {
      .el-checkbox__inner {
        background-color: #ffbe00;
        border-color: #ffbe00;
      }
    }
  }
}
::v-deep .checked3 {
  .el-checkbox__input {
    &.is-checked {
      .el-checkbox__inner {
        background-color: #e31e15;
        border-color: #e31e15;
      }
    }
  }
}
::v-deep .checked4 {
  .el-checkbox__input {
    &.is-checked {
      .el-checkbox__inner {
        background-color: #4d4d4d;
        border-color: #4d4d4d;
      }
    }
  }
}
.el-radio-time1 {
  position: absolute;
  margin: -20px 0 0 250px;
  z-index: 9999;
}
::v-deep  .el-radio-button__inner {
  font-size: 12px !important;
  width: 50px;
}
.analysis{
  position: absolute;
  font-size: 18px;
  line-height: 35px;
  width: 280px;
  height: 30px;
  text-align: center;
  // color: #bfe7f3;
margin: -25px 0 0 150px;
background: linear-gradient(to right, #2D7188, #1C3345); 
}
</style>
